<?php
    defined('_VALID_MOS') or die(include_once("../../404.php"));

    $sql = "SELECT I_ID, I_Code, I_Alias, I_Title, I_Description, I_Detail, I_Image, I_CategoryID, I_Price, Date_FORMAT(I_CreatedDate, '%d/%m/%Y') As CreatedDate, Date_FORMAT(I_ModifiedDate, '%d/%m/%Y') As ModifiedDate, I_State
            FROM items WHERE I_State = 1
        	ORDER BY I_ID DESC";
    $cmd = $mysqli->prepare($sql);
    $cmd->execute() or die($mysqli->error);
    $cmd->bind_result($ID, $code, $alias, $title, $description, $detail, $image, $categoryID, $price, $createdDate, $modifiedDate, $state);
    $cmd->store_result();

    include("protected/front_end_paging.php");

    if (!isset($_GET["page"]))
        $p = 1; else
        $p = $_GET["page"];
    $pager = Pager::getPagerData($cmd->num_rows, 9, $p);
    $i = 1;
?>

<div id="component">

    <!-- sub component --> 
    <div id="sub_component">

        <!-- title bar -->
        <div class="right_title_bar_background">
            <div class="left_title_bar_background">
                <div class="center_title_bar_background">
                    <div class="title_bar">
                        Sản phẩm mới
                    </div>
                </div>
            </div>
        </div>
        <!-- end title bar -->



        <!-- com_category -->
        <div class="com_category">
                <?php while ($cmd->fetch())
                    {
                        if ($i > $pager->offset && $i <= $pager->limit)
                        {
                            ?>
                        <div class="item">	 

            <?php
            //echo '<div class="hovergallery">';
            //echo "<div class=\"image\"><a href=./com_item/item/$alias/$ID.csp><img src=\"$image\"></a></div>";
            //echo '</div>';
            ?>     





                            <div class="image">
                                <div id="rollover">  
                                    <a href="<?php echo "./com_item/item/$alias/$ID.csp" ?>">
                                        <img src="<?php echo $image ?>" />
                                        <span><img src="<?php echo $image ?>"/></span>
                                    </a>                                                                 
                                </div>
                            </div>






                            <div class="d_title"><a href="<?php echo "./com_item/item/$alias/$ID.csp"; ?>"><?php echo $title; ?></a></div>                                
                            <div class="itemCode">Mã: &nbsp;<?php echo $code; ?></div>  
                            <div class="price">Giá: <b><?php echo $price; ?></b></div>	       



                            <div class="button">
                                <a class="button" href="<?php echo "./com_item/item/$alias/$ID.csp"; ?>">Chi tiết</a>
                            </div>



                        </div> 

                    <?php
                    }
                    $i++;
                }
            ?>
            <div class="clear"></div>

            <?php
                //if($cmd->num_rows > 16){						
                //$startposition = $pager->offset + 16;
                //$sql1 = "SELECT I_ID,I_Code,I_Alias,I_Title,I_Description,I_Detail,I_Image,I_CategoryID, I_Price,Date_FORMAT(I_CreatedDate, '%d/%m/%Y') As CreatedDate, Date_FORMAT(I_ModifiedDate, '%d/%m/%Y') As ModifiedDate, I_State
                // FROM items 
                //ORDER BY CreatedDate DESC limit $startposition,16";
                //$cmd1 = $mysqli->prepare($sql1);
                //$cmd1->bind_param("s", $_GET["alias"]);
                //$cmd1->execute() or die($mysqli->error);
                //$cmd1->bind_result($subID, $subCode, $subAlias, $subTitle, $subDescription, $subDetail, $subImage, $subCategoryID, $subPrice, $subCreatedDate, $subModifiedDate, $subState);
                //$cmd1->store_result(); 
            ?>	
            <!--																					
                                    <div class="utility">
                                            <ul>
                                                    <li><a href="<?php //echo $_SERVER['REQUEST_URI'] . "#";?>"><img src="templates/default/images/icon_dautrang.gif"></a></li>
                                            </ul>
                                    </div>	
            -->				

<?php
    //echo "<div class=\"page_num\"><ul>";
    //echo $pager->paging .  "<li> Trang " . $pager->page . " của " . $pager->numPages . "</li>"; 
    //echo "</ul></div>";
    //} 
?>

        </div>

        <!-- bottom bar background -->
        <div class="bottom_bar_background"></div>
        <!-- end bottom bar background -->
    </div>
</div>